<?php

// +----------------------------------------------------------------------
// | 柠檬开发框架
// +----------------------------------------------------------------------
// | 零门槛、轻代码、响应式、清爽、简洁
// +----------------------------------------------------------------------
// | 本项目基于EasyAdmin进行二次开发
// +----------------------------------------------------------------------
// | 相关技术文档可参考：http://easyadmin.99php.cn/docs/index.html
// +----------------------------------------------------------------------


namespace app\admin\controller\lemon;


use app\admin\traits\Curd;
use app\common\controller\AdminController;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use think\App;
use DtApp\Bt\BtException;
use DtApp\Bt\Firewall;
use DtApp\Bt\Soft;

/**
 * Class Index
 * @package app\admin\controller\lemon
 * @ControllerAnnotation(title="柠檬助手")
 */
class Index extends AdminController
{
    /**
     * @NodeAnotation(title="测试")
     */
    public function index()
    {
        echo "<textarea style=\"width:460px;height:160px;margin:auto;margin-top:50px;display: block;text-align:center;\" disabled>\n\n\nHello World\n\n  这是柠檬开发框架的测试程序，很高兴与你见面。这是一个零门槛、轻代码、响应式、清爽、简洁的开发框架，通过该项目您可以快速的进行各种门户网站、应用系统及接口项目的开发工作。--2021年06月09日23:06:02</textarea>";
        $config = [
            'key' => sysconfig('baota','panel_token_value'),
            'panel' => sysconfig('baota','panel_url_value'),
        ];
        echo "<table border=\"1\" style=\"width:80%;margin:auto;margin-top:20px;border-collapse: collapse;border: solid 1px #ccc;table-layout:fixed;\"> <tr> <th colspan=\"5\">宝塔面板</th> </tr> ";
        try {
            $firewall = new Firewall($config);
            echo "<tr> <td colspan=\"5\">防火墙</td></tr>";
            echo "<tr> <td width=\"5%\">编号</td> <td>端口</td> <td>说明</td> <td>添加时间</td> <td>状态</td> </tr>";
            $status=[0=>'未使用',2=>'正常'];
            foreach ($firewall->getList()['data'] as $key => $value) {
                echo "<tr> <td>{$value['id']}</td> <td>{$value['port']}</td> <td>{$value['ps']}</td> <td>{$value['addtime']}</td> <td>{$status[$value['status']]}</td> </tr>";
            }
            echo "<tr> <td colspan=\"5\">面板日志</td></tr>";
            echo "<tr> <td width=\"5%\">编号</td> <td>用户</td> <td>操作类型</td> <td width=\"150px\">详情</td> <td>操作时间</td> </tr>";
            foreach ($firewall->getLog()['data'] as $key => $value) {
                echo "<tr> <td>{$value['id']}</td> <td>{$value['username']}</td> <td>{$value['type']}</td> <td width=\"350px\" style=\"word-wrap: break-word;word-break:break-all;\">{$value['log']}</td> <td>{$value['addtime']}</td> </tr>";
            }
        } catch (BtException $e) {
            var_dump($e->getMessage());
        }
        echo "</table>";
    }
}